package com.xing.binbackend.pattern.adapter24.ecommerce;

import com.xing.binbackend.pattern.adapter24.ecommerce.model.*;
import org.springframework.stereotype.Component;

//**4. 新版支付适配器（类似结构）**
@Component
public class WechatNewAdapter implements IPayment {
    private final WechatPaySDKNew newPay;

    public WechatNewAdapter(WechatPaySDKNew newPay) {
        this.newPay = newPay;
    }

    @Override
    public PayResult pay(PayRequest request) {
        PayRequestNew newRequest = new PayRequestNew();
        newRequest.setMchOrderNo(request.getOrderId());
        PayResponseNew response = newPay.doPay(newRequest);
        return new PayResult(response.getCode() == 200, response.getTransactionId(),
                response.getTransactionId(), response.getCode() == 200 ? null :
                response.getMessage());
    }
}
